package com.wind.controller;

import com.wind.entity.User;
import com.wind.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class UserController {

  @Autowired
  private UserService userService;

  @RequestMapping("/login")
  public Map<String, Object> login(User user) {

    log.info("用户：[{}]", user.getName());
    log.info("密码：[{}]", user.getPassword());

    Map<String, Object> map = new HashMap<>();

    try {
      User userDB = userService.login(user);
      map.put("statu", true);
      map.put("msg", "认证成功~！");

    }catch (Exception e) {
      e.printStackTrace();
      map.put("statu", false);
      map.put("msg", "认证失败~！");
    }
    return map;
  }
}
